package com.googlecode.httpfilter;

import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.log4j.Logger;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponse;

import com.googlecode.httpfilter.filter.HttpDownstreamFilter;
import com.googlecode.httpfilter.filter.HttpFilter;
import com.googlecode.httpfilter.filter.TimestampFilter;


/**
 * Hello world!
 * 
 */
public class App {

	private static final Logger logger = Logger.getLogger(App.class);
	
	public App() {

		Configurer cfg = new Configurer();
		
		final HttpFilterServer server = new HttpFilterServer(cfg, craeteHttpFilters());
		
		server.start();
		
		Runtime.getRuntime().addShutdownHook(new Thread(){

			@Override
			public void run() {
				server.stop();
			}
			
		});
		
	}
	
	private Set<HttpFilter> craeteHttpFilters() {
		
		Set<HttpFilter> filters = new LinkedHashSet<HttpFilter>();
		
		filters.add(new TimestampFilter());
		
		filters.add(new HttpDownstreamFilter() {
			
			@Override
			public void process(HttpRequest req, HttpResponse resp) {
				logger.warn("uri="+req.getUri()+";resp_status="+resp.getStatus());
			}
		});
		
		return filters;
		
	}
	

	public static void main(String[] args) {

		new App();

	}
}
